<template>
	<view class="container">
		<!--切换-->
		<view class="flex-row tabs">
			<view @click="toggleTab(0)" class="tab" :class="{active: tabIndex == 0}">
				<text>模拟考试</text>
			</view>
			<view @click="toggleTab(1)" class="tab" :class="{active: tabIndex == 1}">
				<text>正式考试</text>
			</view>
			<view @click="toggleTab(2)" class="tab" :class="{active: tabIndex == 2}">
				<text>日常答题</text>
			</view>
		</view>
		<!--列表-->
		<scroll-view v-if="list.length" @scrolltolower="getNextPageData" scroll-y="true" class="scroll">
			<view v-for="(item, index) in list" :key="index" @click="toDetail(item.id)" class="card">
				<view class="title flex-row">
					<view class="name">{{ item.name }}</view>
				</view>
				<view class="item">{{ item.num }}道题，{{ item.minuts }}分钟，得分{{ item.point }}</view>
				<view class="item">答题时间：{{ item.addtime }}</view>
				<view class="btn">查看记录</view>
			</view>
			<view class="nodata">没有更多了~</view>
		</scroll-view>
		<view v-else class="nodata">没有更多了~</view>
	</view>
</template>

<script>
export default{
	data(){
		return {
			tabIndex: 0,
			userid: uni.getStorageSync('userid'),
			page: 1,
			total: 1,
			list: []
		}
	},
	onLoad(){
		this.getList();
	},
	methods: {
		// 切换tab
		toggleTab(index){
			this.tabIndex = index;
			this.page = 1;
			this.list = [];
			this.getList();
		},
		toDetail(id){
			uni.navigateTo({
				url: 'recordDetail?id='+id
			});
		},
		// 获取列表
		getList(){
			let _this = this;
			uni.request({
				url: this.$API.edutExamRecordList,
				data: {
					userid: this.userid, 
					type: this.tabIndex + 1 ,
				},
				header: this.$API.get_head(),
				success: (res)=>{
					_this.total = res.data.total;
					
					// 判断是第一页还是后续页
					let data = res.data.rows;
					if(_this.page == 1){
						_this.list = data;
					}else{
						_this.list = _this.list.concat(data);
					}
				}
			})
		},
		// 分页加载
		getNextPageData(){
			console.log(1);
			this.page++;
			if(this.page < this.total){
				this.getList();
			}
		}
	}
}
</script>

<style scoped>
.scroll{
	height: calc(100vh - 80upx);
}
/*卡片*/
.card{
	margin: 20upx 20upx 0;
	border-radius: 16upx;
	background: #fff;
	padding: 14upx 20upx 8upx;
	border: 2upx solid #F6F6F6;
	box-shadow: 0 0 4upx #eee;
	position: relative;
}
.card.danger{
	background: #fff;
	margin: 0 20upx 20upx;
}
.card .title{
	margin-bottom: 6upx;
}
.card .title view{
	height: 42upx;
	font-size: 28upx;
}
.card .title view.name{
	text-indent: 20upx;
	font-weight: bold;
	position: relative;
}
.card .title view.name::before{
	content: '';
	width: 10upx;
	height: 26upx;
	background: #5F96F2;
	border-radius: 4upx;
	position: absolute;
	top: 14upx;
	left: 0;
}
.card .btn{
	padding: 0;
	color: #fff;
	width: 140upx;
	height: 48upx;
	font-size: 24upx;
	line-height: 48upx;
	border-radius: 6upx;
	text-align: center;
	background: #5F96F2;
	position: absolute;
	bottom: 20upx;
	right: 20upx;
}
	
/*tab切换*/
.tabs{
	height: 80upx;
	background: #fff;
	justify-content: space-around;
}
.tabs .tab{
	text-align: center;
	width: calc(100% / 3);
	position: relative;
}
.tabs .tab.active{
	color: #157FC2;
	position: relative;
}
.tabs .tab.active::after{
	content: '';
	width: 120upx;
	height: 6upx;
	background: #157FC2;
	position: absolute;
	bottom: -10upx;
	left: calc(50% - 62upx);
}
.tabs .tab view{
	width: 30upx;
	height: 30upx;
	color: #fff;
	font-size: 20upx;
	text-align: center;
	line-height: 30upx;
	border-radius: 50%;
	background: #FF6E03;
	position: absolute;
	top: -4upx;
	right: -20upx;
}
</style>
